//
//  Date+Extension.swift
//  Kosspot
//
//  Created by 李鑫 on 2025/7/22.
//


import Foundation

extension Date {
    enum DateFormatStyle {
        case full       // 2025年7月22日 星期二
        case long       // 2025年7月22日
        case medium     // 2025-07-22 14:30
        case short      // 07-22 14:30
        case timeOnly   // 14:30:15
        case HMOnly   // 14:30
        case bias   // 2025/4/22
        case custom(String)
    }
    
    func toString(style: DateFormatStyle = .medium, locale: Locale = .current) -> String {
        let formatter = DateFormatter()
        formatter.locale = locale
        
        switch style {
        case .full:
            formatter.dateStyle = .full
            formatter.timeStyle = .short
        case .long:
            formatter.dateStyle = .long
            formatter.timeStyle = .none
        case .medium:
            formatter.dateFormat = "yyyy-MM-dd HH:mm"
        case .short:
            formatter.dateFormat = "MM-dd HH:mm"
        case .timeOnly:
            formatter.dateFormat = "HH:mm:ss"
        case .custom(let format):
            formatter.dateFormat = format
        case .HMOnly:
            formatter.dateFormat = "HH:mm"
        case .bias:
            formatter.dateFormat = "yyyy/MM/dd"
        }
        
        return formatter.string(from: self)
    }
}

